home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Toolbox / Menu 'cicn' Fun / Source / menu 'cicn' fun.c
Encoding:
Text File  |  1996-09-17  |  1.8 KB  |  101 lines  |  [TEXT/CWIE]

  1.     //
  2.     //    It's an unfortunately little-known fact that 'cicn's can be many
  3.     //    sizes, and not only that, but that any size 'cicn' can be put into
  4.     //    a menu item. It's probably not good HI to put in 'cicn's of sizes
  5.     //    other than 32x32 or 16x16; happily, this covers the sizes developers
  6.     //    want most.
  7.     //
  8.     //    Complaints and kudos to:
  9.     //
  10.     //        Pete Gontier
  11.     //        Apple Macintosh Developer Technical Support
  12.     //        <gurgle@apple.com>
  13.     //
  14.  
  15. #define OLDROUTINELOCATIONS        0
  16. #define OLDROUTINENAMES            0
  17. #define SystemSevenOrLater        1
  18.  
  19. #ifndef __FONTS__
  20. #    include <Fonts.h>
  21. #endif
  22.  
  23. #ifndef __DIALOGS__
  24. #    include <Dialogs.h>
  25. #endif
  26.  
  27. #ifndef __RESOURCES__
  28. #    include <Resources.h>
  29. #endif
  30.  
  31. static Boolean gQuitting;
  32.  
  33. static pascal OSErr InitMac (void)
  34. {
  35.     MaxApplZone ( );
  36.     InitGraf (&(qd.thePort));
  37.     InitFonts ( );
  38.     InitWindows ( );
  39.     InitMenus ( );
  40.     TEInit ( );
  41.     InitDialogs (nil);
  42.  
  43.     return noErr;
  44. }
  45.  
  46. static pascal void Command (long ms)
  47. {
  48.     short    menuID = ms >> 16,
  49.             menuItem = ms;
  50.  
  51.     if (menuID == 129)
  52.     {
  53.         gQuitting = true;
  54.     }
  55. }
  56.  
  57. static pascal void HandleEvent (const EventRecord *eventP)
  58. {
  59.     if (eventP->what == mouseDown)
  60.     {
  61.         WindowRef whichWindow;
  62.         short partCode = FindWindow (eventP->where, &whichWindow);
  63.         if (partCode == inMenuBar)
  64.         {
  65.             long ms = MenuSelect (eventP->where);
  66.             if (ms) Command (ms);
  67.             HiliteMenu (0);
  68.         }
  69.     }
  70. }
  71.  
  72. static pascal Boolean SetUpMenuBar (void)
  73. {
  74.     Boolean result = false;
  75.     Handle mBar = GetNewMBar (128);
  76.     if (!ResError ( ) && mBar)
  77.     {
  78.         SetMenuBar (mBar);
  79.         AppendResMenu (GetMenuHandle (130), 'DRVR');
  80.         DrawMenuBar ( );
  81.         result = true;
  82.         ReleaseResource (mBar);
  83.     }
  84.     return result;
  85. }
  86.  
  87. void main (void)
  88. {
  89.     if (!InitMac ( ) && SetUpMenuBar ( ))
  90.     {    
  91.         do
  92.         {
  93.             EventRecord event;
  94.             InitCursor ( );
  95.             WaitNextEvent (everyEvent, &event, -1, nil);
  96.             HandleEvent (&event);
  97.         }
  98.         while (!gQuitting);
  99.     }
  100. }
  101.